home *** CD-ROM | disk | FTP | other *** search
- Path: nntphub.cb.att.com!not-for-mail
- From: ka@socrates.hr.att.com (Kenneth Almquist)
- Newsgroups: comp.lang.ada,comp.lang.c++
- Subject: Re: on OO differnces between Ada95 and C++
- Date: 28 Feb 1996 00:45:29 GMT
- Organization: AT&T Bell Laboratories, Columbus, Ohio
- Message-ID: <4h08j9$f7v@nntpa.cb.att.com>
- References: <4gbq7q$g08@qualcomm.com> <3129F185.41C6@Rational.COM> <4gi413$qo1@druid.borland.com> <312D8EF7.167E@Rational.COM>
- NNTP-Posting-Host: socrates.hr.att.com
-
- Jerome Desquilbet <jDesquilbet@Rational.COM> asks:
- > Pete,
- > What is this "one definition rule"? Could you point me to the
- > appropriate C++ Draft Standard location?
-
- I'm not Pete, but I happen to know the answer. See section 3.2 in the
- April draft. The relevant paragraph reads:
-
- 7 There can be more than one definition of a class type in a program
- provided that each definition appears in a different translation unit
- and the definitions describe the same type.
-
- > It seems that in C++, every encapsulation can be legally broken,
- > essentially because of _independent_ compilation that allows
- > redefinitions of the same class.
-
- No, your example is not legal. The draft continues:
-
- 8 No diagnostic is required for a violation of the ODR rule.
-
- Using the language of the Ada RM, a program which violates the ODR
- is erroneous. The proposed standard says NOTHING about the run time
- behavior of your example.
-
- To see some of the other implications of this, suppose that I'm
- developing some code and need a rectangle class. I write:
-
- class Rectange {
- Point lower_left_corner;
- int height;
- int width;
- };
-
- I unit test my code and it works fine. Now suppose that while I'm
- doing this, one of my co-workers is also developing code for the same
- project, and defines the type:
-
- class Rectange {
- Point lower_left_corner;
- Point upper_right_corner;
- };
-
- Like me, he unit tests his code and it works. But when we build the
- entire program, the program violates the ODR because it contains two
- different defintions of Rectangle. The standard permits the program
- to fail in surprising and interesting ways. This makes it difficult
- to develope large programs in standard C++!
-
- The emphasis here is of course on "standard." The programmers' intents
- were that the two Rectangle classes be distinct types, and that the
- compiler ignore the fact that they happen to have the same name. An
- implementation may do precisely that, and perhaps all implementations
- will. The designers of Ada were concerned enough about programming
- in the large to address this sort of issue in the standard itself
- rather than leaving it as a "quality of implementation" issue.
- Kenneth Almquist
-